package com.example.test.责任连;


import com.example.test.责任连.impl.SourceConditionHandler;
import com.example.test.责任连.impl.SourceConfigHandler;
import com.example.test.责任连.impl.SourceDeviceHandler;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hzj@jovision.com
 * @Date 2020/12/5 上午10:47
 * @Description 事件源操作逻辑工厂类
 */
@Component
public class SourceHandlerFactory implements ApplicationContextAware {
    private static Map<String, AbstractSourceHandler> handlerMap = new HashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        handlerMap.put("1", applicationContext.getBean(SourceDeviceHandler.class));
        handlerMap.put("2", applicationContext.getBean(SourceConditionHandler.class));
        handlerMap.put("3", applicationContext.getBean(SourceConfigHandler.class));
    }

    public AbstractSourceHandler getHandler(String type) {
        return handlerMap.get(type);
    }


}
